package KK.Game
{ 
	import KK.EMVC.Control.Control;
	import KK.GameBase.Events.SceneEvent;
	import KK.GameBase.Events.SceneIndexEvent;
	import KK.GameBase.IEventBase;
	import KK.GameBase.IMessageFollowers;
	import KK.GameBase.IMessageQueue;
	import KK.GameBase.MSGEvent;
	import KK.GameBase.SpriteBase;
	import KK.System.System;
	
	import flash.events.MouseEvent;
	import flash.system.Security;
	import flash.utils.Dictionary;
	
	//760X560 小的
	//1860X970 大
	public class BaseMain extends SpriteBase implements IMessageFollowers , IEventBase
	{
		
		
//		private var _hanlder:MainHanlder;
		protected var _event:IMessageQueue;
		private var proxyList:Dictionary;
		
		static public var Width:int;
		static public var Height:int;
		
		public function BaseMain()
		{
			init();
		}
		private function init():void
		{
			proxyList=new Dictionary();
			BindEvent(Control.GetMessageQueue());
//			_hanlder=new MainHanlder();
			
			
//			Security.allowDomain("*");
			
			//			Main.Width=WarConst.WIDTH;
			//			Main.Height=WarConst.HEIGHT;
			
//			BindEvent(MapMessageQueue.GetInstance()); 
		} 
		
		public function BindEvent(event:IMessageQueue):Boolean
		{ 
			this._event=event;
//			_hanlder.BindEvent(_event);
			initEvent();
			return true;
		}
		private function initEvent():void{
			
			AttentionMessage(SceneEvent.ADD_SCENE_CHILD_EVENT);
			AttentionMessage(SceneEvent.REMOVE_SCENE_CHILD_EVENT);
			AttentionMessage(SceneIndexEvent.SET_SCENE_INDEX_EVENT);
			
			
//			_hanlder.Start();
//			KK.System.System.DebugMSG("hanlder loader Start");
		} 
		protected function Publish(event:MSGEvent):void
		{
			_event.Publish(event);
		}
		
		protected function AttentionMessage(msg:String,proxy:Function=null):void
		{
			_event.AttentionMessage(msg,this);
			proxyList[msg]=proxy;
		}
		public function Update(event:MSGEvent):void
		{
			proxyList[event.type]&&proxyList[event.type](event);
			switch(event.type)
			{
				case SceneEvent.ADD_SCENE_CHILD_EVENT:
					this.addChildScene(SceneEvent(event).child,SceneEvent(event).numChild);
					break;
				case SceneEvent.REMOVE_SCENE_CHILD_EVENT:
					this.removeChildScene(SceneEvent(event).child,SceneEvent(event).numChild);
					break;
				case SceneIndexEvent.SET_SCENE_INDEX_EVENT:
					this.setSceneIndex(SceneEvent(event).child,SceneEvent(event).numChild);
					break;
			}
		}
		
		
	}
}